<template>
	<view class="container">
		<view class="bigBox" v-if="!selectTypeShow">
			<view class="top">
				<view class="bold">
					新增店铺
				</view>
				<view class="">
					完成注册，开店创收
				</view>
			</view>
			<view class="content">
				<view class="title">
					选择支付公司 <text class="red">*</text>
				</view>
				<scroll-view style="height: calc(100% - 106rpx)" scroll-y>

					<radio-group @change="radioChange">
						<view class="item" v-for="(item, index) in channelList" :key="item.value">
							<view class="left">
								<image :src="item.logoImgUrl" mode="widthFix"></image>
								<view class="">
									{{item.name}}
								</view>
							</view>

							<radio :value="item.channelNo" :checked="index === current" />
						</view>
					</radio-group>

				</scroll-view>
				<view class="bottom">
					<button class="btn" @click="submitBtn()">确认</button>
				</view>

			</view>

		</view>
		<selectType v-if="selectTypeShow" @updateValue="handleUpdate" :scanResult="selectChannel"></selectType>
	</view>
</template>

<script setup>
	import {
		onLoad,
		onShow
	} from "@dcloudio/uni-app";
	import {
		ref,
		reactive
	} from "vue";
	import {
		showToast
	} from "@/utils/toast";
	import selectType from "./component/index.vue";
	import {

		channelQuery
	} from '@/api/common'
	const selectTypeShow = ref(false)
	const selectChannel = ref(null)
	onLoad((val) => {
		console.log("val888", val)
		selectTypeShow.value = val.selectTypeShow ? val.selectTypeShow : false
	});
	onShow(() => {

		getChannels();
	});

	const channelList = ref([])

	let submitBtn = () => {
		if (!selectChannel.value) {
			showToast("请选择支付公司");
			return false;
		}
		selectTypeShow.value = true

	}
	let handleUpdate = (val) => {
		console.log("val88", val)
		selectTypeShow.value = val
	}

	function radioChange(e) {
		console.log("e=" + JSON.stringify(e))
		selectChannel.value = e.detail.value;
	}

	function getChannels() {
		channelQuery().then((res) => {
				channelList.value = res;
				channel.value = res

				let channelInfomation = channel.value
				// 存储通道信息
				store.setData({
					channelInfomation,
				});
				uni.setStorageSync("channelInfomation", channelInfomation);
			})
			.catch((err) => {
				console.log("err-err", err.data.code)

			});
	}
</script>
<style lang="scss" scoped>
	@import "./index.scss";
</style>
<style lang="scss">
	page {
		background-color: #FFF !important;
	}
</style>